<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>

    <%@include file="../common/include.jsp" %>

        <!DOCTYPE HTML>
        <html>

        <head>
            <base href="<%=basePath%>">
            <title>一级菜单列表</title>


            <body>




                <div class="row" style="margin-top:20px;margin-left:20px">
                    <form id="searchForm" action="${pageContext.request.contextPath}/getSuperMenuList.html" method="post">

                        <div class="col-md-4">

                            <div class="input-group">

                                <c:choose>
                                    <c:when test="${ not empty pages.conditions.name }">
                                        <input type="text" class="form-control" value="${pages.conditions.name }" id="conditions['name']" name="conditions['name']">
                                    </c:when>

                                    <c:otherwise>
                                        <input type="text" class="form-control" placeholder="输入菜单名称模糊查询" id="conditions['name']" name="conditions['name']">
                                    </c:otherwise>
                                </c:choose>



                                <span class="input-group-btn">
	   <button class="btn btn-default" type="submit"   id="btnsearch">查询</button>
	</span>
                            </div>
                        </div>


                        <div class="col-md-2">

                            <a href="addSuperMenuInit.html" class="btn btn-success" style="margin-left:60px; ">增加一级菜单</a>
                        </div>


                    </form>
                </div>


                <!--  {"currPage":1,"totalPages":1,"params":"","conditions":{},"pageSize":10,"totalRecords":6,"isHavePrePage":false,"isHaveNextPage":false,
     "pageDatas":[{"id":1,"name":"系统设置","description":"账号和角色","isuse":true,"icopath":"components/menu01/images/left/syetem_management.png","icopathopen":"components/menu01/images/left/syetem_management.png"},
	                      {"id":2,"name":"商品管理","description":"管理商品","isuse":false,"icopath":"components/menu01/images/left/app.png","icopathopen":"components/menu01/images/left/app.png"},
	                      {"id":6,"name":"菜单管理","description":"用来管理 一级菜单 和二级菜单","isuse":true,"icopath":"components/menu01/images/left/custom.png","icopathopen":"components/menu01/images/left/custom.png"}
                         ]
  } -->
                <div style="margin-left:16px; margin-top:20px;margin-bottom:90px;margin-right:30px">
                    <table class="table table-striped  table-bordered table-hover">
                        <thead>
                            <tr style="background-color:#dcdcdc; ">
                                <th>排序序号</th>
                                <th>菜单名称</th>
                                <th>菜单说明</th>
                                <th>是否可见</th>
                                <th>默认图片地址</th>
                                <th>选中图片地址</th>
                                <th>操作</th>
                            </tr>
                        </thead>

                        <tbody>

                            <c:forEach var="menu" items="${pages.pageDatas}">
                                <tr id="tr_${menu.id }">
                                    <td> ${menu.sortid} </td>
                                    <td> ${menu.name} </td>
                                    <td> ${menu.description}</td>

                                    <td>
                                        <c:choose>
                                            <c:when test="${menu.isuse}">
                                                <input type="checkbox" checked onclick="changFlag(this,${menu.id})">显示
                                            </c:when>

                                            <c:when test="${! menu.isuse}">
                                                <input type="checkbox" onclick="changFlag(this,${menu.id})">显示
                                            </c:when>

                                        </c:choose>
                                    </td>


                                    <td>${menu.icopath}</td>
                                    <td>${menu.icopathopen}</td>

                                    <td>

                                        <a href="updateSuperMenuInit.html?id=${menu.id }" title="修改" class="handleicon"> <i class="fa fa-pencil-square-o"></i></a>

                                        <a href="javascript:void(0)" onclick="deleteById(${menu.id})" class="handleicon" title="删除"> <i class="fa fa-times"></i> </a>
                                    </td>
                                </tr>
                            </c:forEach>
                        </tbody>
                    </table>

                    <!--  使用自己的 分页标签  前面三个是固定的必须参数 后面的url  是请求路径，可以根据情况  加或者不加参数-->

                    <c:if test="${pages.totalPages>1 }">
                        <page:pager pageSize="${pages.pageSize}" currPage="${pages.currPage}" totalRecords="${pages.totalRecords}" url="${pageContext.request.contextPath}/getSuperMenuList.html?conditions['name']=${pages.conditions.name}" />

                    </c:if>


                </div>


            </body>





            <script>
                //传递2个参数 一个是对象本身 一个是 内容ID
                function changFlag(e, id) {
                    /* var ctrl = $("#" + id); */

                    var isUse = 0;

                    if (e.checked == true) {
                        isUse = 1;
                    } else {
                        isUse = 0;
                    }

                    $.ajax({
                        type: 'POST',
                        url: '${pageContext.request.contextPath}/updateSuperMenuFlag.html',
                        data: {
                            "id": id,
                            "flag": isUse
                        },

                        dataType: 'json', //要求服务器返回 json对象 而不是字符串
                        success: function(data) {

                            if (data.code == 1) {

                                layer.msg('更新成功');
                            } else {
                                layer.msg(data.msg);
                            }

                        },
                        error: function() {

                            layer.msg("请求出错，可能连接不上服务器");
                        }

                    })

                }




                /*    通过ajax 提交删除请求 ，根据返回结果 删除本地 表格里的数据，实现无刷新删除 */

                function deleteById(id) {

                    if (confirm('真的要删除一级菜单吗？')) {

                        $.ajax({
                            type: 'POST',
                            url: '${pageContext.request.contextPath}/deleteSuperMenuById.html',
                            data: {
                                "id": id
                            },
                            dataType: 'json', //要求服务器返回 json对象 而不是字符串
                            success: function(data) {

                                if (data.code == 1) {
                                    $("#tr_" + id).remove();

                                    layer.msg('删除成功');
                                } else {
                                    layer.msg(data.msg);
                                }
                            },
                            error: function() {
                                alert("出错");
                            }

                        })

                    }

                }
            </script>



        </html>